#!/usr/bin/perl
# This tool is written as an tool to read the bridge table
# from switches.
# This tool has been written under the GNU license.
# If you have any usable updates, please send me the new version.
# Bernard van de Koppel (bernard@netwerkinformatie.com)

use SNMP_util;


my $IPADDR = $ARGV[0] || die "Oops, no ipaddr specified....";
my $COMM = $ARGV[1] || die "Oops, no community specified....";
my $OID = $ARGV[2] || die "Oops, no oid specified....";
print("Getting info for $IPADDR with comm $COMM ($OID)\n");

$HOST = $COMM . "@" . $IPADDR;
$SNMPVER = "1";
$SNMPSTR = "$HOST" . ":::::" . "$SNMPVER";
print("Getting table.\n");

sub make_hex_string {
   my $str = unpack "H*", shift @_;
   $str =~ s/(..)/:$1/g;
   $str =~ s/^://;
   $str;
} 
$oid = $OID;
print "Trying 'getnext' on $HOST with $oid\n";
  my @ret = &snmpwalk($SNMPSTR, "$oid");
  foreach my $desc (@ret) {
    ($oid, $desc) = split(':', $desc, 2);
    $c1 = substr($desc, 0, 1);
    $c2 = substr($desc, 1, 1);
    $c3 = substr($desc, 2, 1);
    $c4 = substr($desc, 3, 1);
    $c5 = substr($desc, 4, 1);
    $c6 = substr($desc, 5, 1);
    my $Tstring = ord($c1) . ":" . ord($c2) . ":" . ord($c3) . ":" . ord($c4) . ":" . ord($c5) . ":" . ord($c6); 
    my $hex = make_hex_string($desc);
    print "$oid = $desc ($hex)')\n";
  }
